﻿//**************************************************
//CLASS : tcdc_mst_information_group
//AUTHOR : PATTARAWUT CHANNGAM & SUCHIN INPIRUT
//LAST MODIFIED : Monday, February 25, 2013
//**************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Model
{

public class tcdc_mst_information_group
{

     private DBUtil DB;
     public string strConn { get; set; }
     public int information_group_id {get;set;}
     public string information_group_desc {get;set;}
     public string object_type {get;set;}
     public int sorting_group_no {get;set;}
     public string information_group_short {get;set;}

     public tcdc_mst_information_group() {
          this.DB = new DBUtil();
          DB.strConn = strConn;
     }

     public DataTable getById(string id) {

          DataTable dt = new DataTable();
          this.DB = new DBUtil();
          DB.strConn = strConn;

          string sql = "SELECT * FROM tcdc_mst_information_group" + 
                       " WHERE information_group_id = '" + id + "'";

          dt = DB.ExecuteReader(sql);

          return dt;

     }

     public DataTable getByObject(tcdc_mst_information_group obj) {

          DataTable dt = new DataTable();
          this.DB = new DBUtil();
          DB.strConn = strConn;

          string sql = "SELECT * FROM tcdc_mst_information_group " + 
                       "WHERE 1 = 1 ";

          if(obj.information_group_id != null && 
             obj.information_group_id.ToString() != null && 
             obj.information_group_id.ToString() != "0")
          {
               sql += "AND information_group_id LIKE '%" + obj.information_group_id + "%' ";
          }
          if(obj.information_group_desc != null && 
             obj.information_group_desc.ToString() != null && 
             obj.information_group_desc.ToString() != "0")
          {
               sql += "AND information_group_desc LIKE '%" + obj.information_group_desc + "%' ";
          }
          if(obj.object_type != null && 
             obj.object_type.ToString() != null && 
             obj.object_type.ToString() != "0")
          {
               sql += "AND object_type LIKE '%" + obj.object_type + "%' ";
          }
          if(obj.sorting_group_no != null && 
             obj.sorting_group_no.ToString() != null && 
             obj.sorting_group_no.ToString() != "0")
          {
               sql += "AND sorting_group_no LIKE '%" + obj.sorting_group_no + "%' ";
          }
          if(obj.information_group_short != null && 
             obj.information_group_short.ToString() != null && 
             obj.information_group_short.ToString() != "0")
          {
               sql += "AND information_group_short LIKE '%" + obj.information_group_short + "%' ";
          }
          dt = DB.ExecuteReader(sql);

          return dt;

     }

     public int insertData(tcdc_mst_information_group obj) {

          this.DB = new DBUtil();
          DB.strConn = strConn;

          SqlParameter[] prm;
          prm = new SqlParameter[5];

          prm[0] = new SqlParameter("@information_group_desc", SqlDbType.NVarChar,250);
          if(obj.information_group_desc != null && 
             obj.information_group_desc.ToString() != null && 
             obj.information_group_desc.ToString() != "0")
          {
               prm[0].Value = obj.information_group_desc;
          }
          else
          {
               prm[0].Value = DBNull.Value;
          }

          prm[1] = new SqlParameter("@object_type", SqlDbType.NVarChar,250);
          if(obj.object_type != null && 
             obj.object_type.ToString() != null && 
             obj.object_type.ToString() != "0")
          {
               prm[1].Value = obj.object_type;
          }
          else
          {
               prm[1].Value = DBNull.Value;
          }

          prm[2] = new SqlParameter("@sorting_group_no", SqlDbType.Int);
          if(obj.sorting_group_no != null && 
             obj.sorting_group_no.ToString() != null && 
             obj.sorting_group_no.ToString() != "0")
          {
               prm[2].Value = obj.sorting_group_no;
          }
          else
          {
               prm[2].Value = DBNull.Value;
          }

          prm[3] = new SqlParameter("@information_group_short", SqlDbType.NVarChar,50);
          if(obj.information_group_short != null && 
             obj.information_group_short.ToString() != null && 
             obj.information_group_short.ToString() != "0")
          {
               prm[3].Value = obj.information_group_short;
          }
          else
          {
               prm[3].Value = DBNull.Value;
          }

          prm[4] = new SqlParameter("@ReturnValue", SqlDbType.Int);
          prm[4].Direction = ParameterDirection.Output;

          DB.ExecuteNonQueryProc("sp_tcdc_mst_information_group_insert", prm, false);
          return (Int32)prm[4].Value;
     }

     public int updateData(tcdc_mst_information_group obj) {

          this.DB = new DBUtil();
          DB.strConn = strConn;

          SqlParameter[] prm;
          prm = new SqlParameter[5];

          prm[0] = new SqlParameter("@information_group_id", SqlDbType.Int);
          if(obj.information_group_id != null && 
             obj.information_group_id.ToString() != null && 
             obj.information_group_id.ToString() != "0")
          {
               prm[0].Value = obj.information_group_id;
          }
          else
          {
               prm[0].Value = DBNull.Value;
          }
          prm[1] = new SqlParameter("@information_group_desc", SqlDbType.NVarChar,250);
          if(obj.information_group_desc != null && 
             obj.information_group_desc.ToString() != null && 
             obj.information_group_desc.ToString() != "0")
          {
               prm[1].Value = obj.information_group_desc;
          }
          else
          {
               prm[1].Value = DBNull.Value;
          }
          prm[2] = new SqlParameter("@object_type", SqlDbType.NVarChar,250);
          if(obj.object_type != null && 
             obj.object_type.ToString() != null && 
             obj.object_type.ToString() != "0")
          {
               prm[2].Value = obj.object_type;
          }
          else
          {
               prm[2].Value = DBNull.Value;
          }
          prm[3] = new SqlParameter("@sorting_group_no", SqlDbType.Int);
          if(obj.sorting_group_no != null && 
             obj.sorting_group_no.ToString() != null && 
             obj.sorting_group_no.ToString() != "0")
          {
               prm[3].Value = obj.sorting_group_no;
          }
          else
          {
               prm[3].Value = DBNull.Value;
          }
          prm[4] = new SqlParameter("@information_group_short", SqlDbType.NVarChar,50);
          if(obj.information_group_short != null && 
             obj.information_group_short.ToString() != null && 
             obj.information_group_short.ToString() != "0")
          {
               prm[4].Value = obj.information_group_short;
          }
          else
          {
               prm[4].Value = DBNull.Value;
          }

          return DB.ExecuteNonQueryProc("sp_tcdc_mst_information_group_update", prm, false);
     }

     public int deleteData(string id) {

          this.DB = new DBUtil();
          DB.strConn = strConn;

          SqlParameter[] prm;
          prm = new SqlParameter[1];

          prm[0] = new SqlParameter("@information_group_id", id);

          return DB.ExecuteNonQueryProc("sp_tcdc_mst_information_group_delete", prm, false);
     }
}

}

